package com.dingnate.netty.client.demo;

import io.netty.handler.codec.http.HttpMethod;

import java.util.Map;

public class HttpClientUtil {
    static HttpClient client = new HttpClient();

    public static String get(String url) throws Exception {
        return get(url, null);
    }

    public static String get(String url, Map<String, String> headers) throws Exception {
        return client.send(url, "", HttpMethod.GET, headers);
    }

    public static String patch(String url) throws Exception {
        return patch(url, null);
    }

    public static String patch(String url, Map<String, String> headers) throws Exception {
        return client.send(url, "", HttpMethod.PATCH, headers);
    }

    public static String post(String url, String msg) throws Exception {
        return post(url, msg, null);
    }

    public static String post(String url, String msg, Map<String, String> header) throws Exception {
        return client.send(url, msg, HttpMethod.POST, header);
    }

    public static String delete(String url) throws Exception {
        return delete(url, null);
    }

    public static String delete(String url, Map<String, String> header) throws Exception {
        return client.send(url, null, HttpMethod.DELETE, header);
    }

    public static String put(String url, String msg) throws Exception {
        return put(url, msg, null);
    }

    public static String put(String url, String msg, Map<String, String> header) throws Exception {
        return client.send(url, msg, HttpMethod.PUT, header);
    }
}
